import PubSub from "pubsub-js";

function publish<T>(key: string, data: T) {
	PubSub.publish(key, data);
}

function subscribe<T>(key: string, listener: (data: T) => void) {
	PubSub.subscribe(key, (_, data) => listener(data));
}

function unsubscribe(key: string) {
	PubSub.unsubscribe(key);
}

export default {
	publish,
	subscribe,
	unsubscribe,
};
